//
//  UIView+Expend.m
//  YiwiCmstop
//
//  Created by Yiwi on 16/9/30.
//  Copyright © 2016年 Yi. All rights reserved.
//

#import "UIView+Expend.h"

@implementation UIView (Expend)

- (float)x {
    return self.frame.origin.x;
}

- (float)yh {
    return self.frame.origin.y + self.frame.size.height;
}

- (float)xw {
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setX:(float)newX {
    CGRect frame = self.frame;
    frame.origin.x = newX;
    self.frame = frame;
}

- (float)y {
    return self.frame.origin.y;
}

- (void)setY:(float)newY {
    CGRect frame = self.frame;
    frame.origin.y = newY;
    self.frame = frame;
}

- (float)width {
    return self.frame.size.width;
}

- (void)setWidth:(float)newWidth {
    CGRect frame = self.frame;
    frame.size.width = newWidth;
    self.frame = frame;
}

- (float)height {
    return self.frame.size.height;
}

- (void)setHeight:(float)newHeight {
    CGRect frame = self.frame;
    frame.size.height = newHeight;
    self.frame = frame;
}
- (float)centerX{
    return self.center.x;
}
- (void)setCenterX:(float)centerX{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}
- (float)centerY{
    return self.center.y;
}
- (void)setCenterY:(float)centerY{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}
- (void)clearView {
    for (UIView *v in self.subviews) {
        [v removeFromSuperview];
    }
}

- (void)removeViewWithTag:(NSInteger)viewTag {
    UIView *view = [self viewWithTag:viewTag];
    [view removeFromSuperview];
}

- (void)setSize:(CGSize)size{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}
- (CGSize)size{
    return self.frame.size;
}


- (void)addTopBorderWithColor:(UIColor *)color andWidth:(CGFloat) borderWidth {
    CALayer *border = [CALayer layer];
    border.backgroundColor = color.CGColor;
    
    border.frame = CGRectMake(0, 0, self.frame.size.width, borderWidth);
    [self.layer addSublayer:border];
}

- (void)addBottomBorderWithColor:(UIColor *)color andWidth:(CGFloat) borderWidth {
    CALayer *border = [CALayer layer];
    border.backgroundColor = color.CGColor;
    
    border.frame = CGRectMake(0, self.frame.size.height - borderWidth, self.frame.size.width, borderWidth);
    
    [self.layer addSublayer:border];
}




@end
